import { Component, OnInit, HostBinding} from '@angular/core';
import { Project } from '../../domain/project.domain';
import { MatDialog } from '@angular/material';
import { CreateProjectComponent } from '../create-project/create-project.component';
import { InviteComponent } from '../invite/invite.component';
import { ConfirmDialogComponent } from '../../shared/confirm-dialog/confirm-dialog.component';
import { cardAnim } from '../../anims/card.anim';
import { routerAnim } from '../../anims/router.anim';
import { listAnim } from '../../anims/list.anim';

@Component({
  selector: 'app-project-list',
  templateUrl: './project-list.component.html',
  styleUrls: ['./project-list.component.scss'],
  animations: [cardAnim, routerAnim, listAnim]
})
export class ProjectListComponent implements OnInit {
  @HostBinding('@routerAnim') state;
  projects: Project[];
  constructor(private dialog: MatDialog) { }

  ngOnInit() {
    this.projects = [{ title: '企业协作平台', coverImg: 'http://placehold.it/320x150', desc: '这是企业协作平台。' },
      { title: '凤凰新华erp', coverImg: 'http://placehold.it/320x150', desc: '这是凤凰新华erp。' }];
  }
  openCreateProjectDialog(e) {
    const dialogRef = this.dialog.open(CreateProjectComponent, { data: "This is what i want to say." });
    dialogRef.afterClosed().subscribe(rt => this.projects.push({ title: '企业协作平台', coverImg: 'http://placehold.it/320x150', desc: '这是企业协作平台。' }));
  }
  inviteBtnClickedHandler(e) {
    const dialogRef = this.dialog.open(InviteComponent);
  }
  delBtnClickedHandler(e) {
    const dialogRef = this.dialog.open(ConfirmDialogComponent, { data: {title:"警告",content:"您确认删除该项目吗?"}});
    dialogRef.afterClosed().subscribe(data => console.log(`项目${data}`));
  }
}
